package cn.com.ddapp.ddm.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.BaseActivity;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.Entity;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.util.SPUtils;

public class NewAlterMobileActivity extends BaseActivity {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.titletext)
    TextView titletext;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_idCard)
    EditText etIdCard;
    @BindView(R.id.bt_commit)
    Button btCommit;

    @Override
    public void initView() {
        titletext.setText(R.string.altermobile);
    }

    @Override
    public void initData() {

    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_new_alter_mobile;
    }

    @Override
    protected String getFragmentTag() {
        return null;
    }

    @OnClick({R.id.back,R.id.bt_commit})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.back :
                finish();
                break;
            case R.id.bt_commit :
                String userId = SPUtils.getStringData(this, SPUtils.USERID);
                String name = etName.getText().toString();
                String idCard = etIdCard.getText().toString();
                if ("".equals(name)){
                    BaseApplication.getIntstance().showToast("请输入名字", Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                }else if ("".equals(idCard)){
                    BaseApplication.getIntstance().showToast("请输入身份证号码", Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                }else {
                    OkUtilCallback callback = new OkUtilCallback() {
                        @Override
                        public void onMyResponse(String response, int id) {
                            Gson gson = new Gson();
                            Entity entity = gson.fromJson(response, Entity.class);
                            if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult())) && entity.getLogin()) {
                                BaseApplication.getIntstance().showToast("请检查网络", Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                            } else if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                                BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.TOP);
                            } else if ((AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                                BaseApplication.getIntstance().showToast("认证成功", Toast.LENGTH_SHORT, 0, Gravity.TOP);
                                Intent intent = new Intent(NewAlterMobileActivity.this,OldAlterMobileActivity.class);
                            }
                        }
                    };
                    OKUtilAPI.post(OKUtilAPI.nameAuthOk,"userId="+userId+"&name="+name+"&idcard="+idCard,callback);
                }
                break;
        }
    }

}
